<template>
  <div class="home">
    <!-- 轮播图 -->
    <section class="hero-section">
      <div class="hero-slider" ref="heroSlider">
        <div 
          class="hero-slide" 
          v-for="(slide, index) in heroSlides" 
          :key="index"
          :class="{ active: currentSlide === index }"
          :style="{ backgroundImage: `url(${slide.background})` }"
        >
          <div class="hero-content">
            <div class="container">
              <h1 class="hero-title" v-html="$t(slide.titleKey)"></h1>
              <p class="hero-subtitle">{{ $t(slide.subtitleKey) }}</p>
              <div class="hero-actions">
                <el-button 
                  type="primary" 
                  size="large" 
                  @click="slide.action"
                  :icon="slide.buttonIcon"
                >
                  {{ $t(slide.buttonTextKey) }}
                </el-button>
                <el-button 
                  v-if="slide.secondaryButton" 
                  size="large" 
                  @click="slide.secondaryAction"
                >
                  {{ $t(slide.secondaryButtonTextKey) }}
                </el-button>
              </div>
            </div>
          </div>
          <div class="hero-overlay"></div>
        </div>
        
        <!-- 导航按钮 -->
        <div class="hero-nav">
          <button class="nav-btn prev" @click="prevSlide">
            <i class="el-icon-arrow-left"></i>
          </button>
          <button class="nav-btn next" @click="nextSlide">
            <i class="el-icon-arrow-right"></i>
          </button>
        </div>
        
        <!-- 指示器 -->
        <div class="hero-indicators">
          <button 
            v-for="(slide, index) in heroSlides" 
            :key="index"
            class="indicator"
            :class="{ active: currentSlide === index }"
            @click="goToSlide(index)"
          ></button>
        </div>
        
        <!-- 自动播放控制 -->
        <div class="hero-controls">
          <button class="control-btn" @click="toggleAutoPlay">
            <i :class="autoPlay ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
          </button>
        </div>
      </div>
    </section>

    <!-- 产品中心 -->
    <section class="products-section">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">{{ $t('home.products.title') }}</h2>
          <p class="section-subtitle">{{ $t('home.products.subtitle') }}</p>
        </div>
        
        <div class="products-grid">
          <div class="product-card" v-for="product in products" :key="product.id">
            <div class="product-image">
              <img :src="product.image" :alt="product.name" @error="handleImageError">
            </div>
            <div class="product-content">
              <h3 class="product-name">{{ $t(product.nameKey) }}</h3>
              <p class="product-category">{{ $t(product.categoryKey) }}</p>
              <el-button type="text" @click="viewProduct(product)">{{ $t('home.products.learnMore') }}</el-button>
            </div>
          </div>
        </div>
        
        <div class="section-footer">
          <el-button type="primary" @click="$router.push('/products')">{{ $t('home.products.viewAll') }}</el-button>
        </div>
      </div>
    </section>



    <!-- 新闻动态 -->
    <section class="news-section">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">{{ $t('home.news.title') }}</h2>
          <p class="section-subtitle">{{ $t('home.news.subtitle') }}</p>
        </div>
        
        <div class="news-grid">
          <div class="news-card" v-for="news in newsList" :key="news.id">
            <div class="news-image">
              <img :src="news.image" :alt="news.title" @error="handleImageError">
              <div class="news-category">{{ getCategoryName(news.category) }}</div>
            </div>
            <div class="news-content">
              <div class="news-meta">
                <span class="news-date">{{ formatDate(news.date) }}</span>
              </div>
              <h3 class="news-title">{{ news.title }}</h3>
              <p class="news-desc">{{ news.summary }}</p>
              <div class="news-tags">
                <el-tag 
                  v-for="tag in news.tags" 
                  :key="tag" 
                  size="small" 
                  type="info"
                >
                  {{ tag }}
                </el-tag>
              </div>
              <div class="news-actions">
                <el-button type="text" @click="readNews(news)">{{ $t('home.news.readMore') }}</el-button>
              </div>
            </div>
          </div>
        </div>
        
        <div class="section-footer">
          <el-button type="primary" @click="$router.push('/news')">{{ $t('home.news.viewMore') }}</el-button>
        </div>
      </div>
    </section>

    <!-- 关于我们 -->
    <section class="contact-section">
      <div class="container">
        <div class="contact-content">
          <h2 class="contact-title">{{ $t('home.about.title') }}</h2>
          <p class="contact-desc">{{ $t('home.about.subtitle') }}</p>
          <div class="contact-actions">
            <el-button type="primary" size="large" @click="goToAbout">{{ $t('home.about.contactUs') }}</el-button>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      currentSlide: 0,
      autoPlay: true,
      autoPlayInterval: null,
             heroSlides: [
         {
           titleKey: 'home.hero.slide1.title',
           subtitleKey: 'home.hero.slide1.subtitle',
           background: 'https://images.unsplash.com/photo-1518709268805-4e9042af2176?w=1920&h=600&fit=crop',
           buttonTextKey: 'home.hero.slide1.buttonText',
           buttonIcon: 'el-icon-info',
           action: () => this.learnMore(),
           secondaryButton: true,
           secondaryButtonTextKey: 'home.hero.slide1.secondaryButtonText',
           secondaryAction: () => this.viewProducts()
         },
         {
           titleKey: 'home.hero.slide2.title',
           subtitleKey: 'home.hero.slide2.subtitle',
           background: 'https://images.unsplash.com/photo-1551434678-e076c223a692?w=1920&h=600&fit=crop',
           buttonTextKey: 'home.hero.slide2.buttonText',
           buttonIcon: 'el-icon-cpu',
           action: () => this.viewAI(),
           secondaryButton: true,
           secondaryButtonTextKey: 'home.hero.slide2.secondaryButtonText',
           secondaryAction: () => this.viewWhitePaper()
         },
         {
           titleKey: 'home.hero.slide3.title',
           subtitleKey: 'home.hero.slide3.subtitle',
           background: 'https://images.unsplash.com/photo-1485827404703-89b55fcc595e?w=1920&h=600&fit=crop',
           buttonTextKey: 'home.hero.slide3.buttonText',
           buttonIcon: 'el-icon-star-on',
           action: () => this.joinCharity(),
           secondaryButton: false
         },
         {
           titleKey: 'home.hero.slide4.title',
           subtitleKey: 'home.hero.slide4.subtitle',
           background: 'https://images.unsplash.com/photo-1451187580459-43490279c0fa?w=1920&h=600&fit=crop',
           buttonTextKey: 'home.hero.slide4.buttonText',
           buttonIcon: 'el-icon-view',
           action: () => this.viewCase(),
           secondaryButton: true,
           secondaryButtonTextKey: 'home.hero.slide4.secondaryButtonText',
           secondaryAction: () => this.viewSolutions()
         }
       ],
      products: [
        {
          id: 1,
          nameKey: 'products.productNames.fixedCamera',
          categoryKey: 'home.products.frontendCategory',
          image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop'
        },
        {
          id: 2,
          nameKey: 'products.productNames.domeCamera',
          categoryKey: 'home.products.frontendCategory',
          image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop&v=2'
        },
        {
          id: 3,
          nameKey: 'products.productNames.ptzCamera',
          categoryKey: 'home.products.frontendCategory',
          image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop&v=3'
        }
      ],

      newsList: [
        {
          id: 1,
          title: '海康威视成为杭州2022年亚运会官方赞助商',
          summary: '助力打造智能亚运，为亚运会提供智能化技术支持和服务，展现中国科技实力',
          category: 'company',
          date: '2022-01-18',
          image: 'https://images.unsplash.com/photo-1518709268805-4e9042af2176?w=800&h=400&fit=crop',
          tags: ['亚运会', '赞助商', '智能化']
        },
        {
          id: 2,
          title: '海康威视发布新一代AI开放平台',
          summary: '基于深度学习技术，为各行业提供更智能、更高效的AI解决方案',
          category: 'product',
          date: '2025-07-28',
          image: 'https://images.unsplash.com/photo-1551434678-e076c223a692?w=800&h=400&fit=crop',
          tags: ['AI平台', '深度学习', '智能化']
        },
        {
          id: 3,
          title: '2025年智慧城市发展趋势报告发布',
          summary: '深度分析智慧城市建设现状，预测未来发展方向和技术趋势',
          category: 'industry',
          date: '2025-07-20',
          image: 'https://images.unsplash.com/photo-1485827404703-89b55fcc595e?w=400&h=300&fit=crop',
          tags: ['智慧城市', '趋势报告', '技术预测']
        }
      ]
    }
  },
  methods: {
    // 轮播图方法
    nextSlide() {
      this.currentSlide = (this.currentSlide + 1) % this.heroSlides.length
    },
    
    prevSlide() {
      this.currentSlide = this.currentSlide === 0 
        ? this.heroSlides.length - 1 
        : this.currentSlide - 1
    },
    
    goToSlide(index) {
      this.currentSlide = index
    },
    
    toggleAutoPlay() {
      this.autoPlay = !this.autoPlay
      if (this.autoPlay) {
        this.startAutoPlay()
      } else {
        this.stopAutoPlay()
      }
    },
    
    startAutoPlay() {
      this.stopAutoPlay()
      this.autoPlayInterval = setInterval(() => {
        this.nextSlide()
      }, 5000)
    },
    
    stopAutoPlay() {
      if (this.autoPlayInterval) {
        clearInterval(this.autoPlayInterval)
        this.autoPlayInterval = null
      }
    },
    
    // 轮播图按钮方法
    learnMore() {
      this.$message.info('了解更多功能开发中...')
    },
    
    viewProducts() {
      this.$router.push('/products')
    },
    
    viewAI() {
      this.$message.info('AI开放平台功能开发中...')
    },
    
    viewWhitePaper() {
      this.$message.info('技术白皮书下载功能开发中...')
    },
    
    joinCharity() {
      this.$message.info('公益计划参与功能开发中...')
    },
    
    viewCase() {
      this.$message.info('案例详情功能开发中...')
    },
    
    viewSolutions() {
      this.$router.push('/solutions')
    },
         viewProduct(product) {
       this.$router.push(`/product/${product.id}`)
     },
    readNews(news) {
      this.$router.push('/news')
    },
    

    
    getCategoryName(category) {
      const categoryMap = {
        company: this.$t('home.news.category.company'),
        tech: this.$t('home.news.category.tech'),
        industry: this.$t('home.news.category.industry'),
        event: this.$t('home.news.category.activity'),
        product: this.$t('home.news.category.product')
      }
      return categoryMap[category] || '其他'
    },
    
    formatDate(date) {
      return new Date(date).toLocaleDateString('zh-CN')
    },
         goToAbout() {
       this.$router.push('/about')
     },
    handleImageError(e) {
      e.target.style.display = 'none'
    }
  },
  
  mounted() {
    this.startAutoPlay()
  },
  
  beforeDestroy() {
    this.stopAutoPlay()
  }
}
</script>

<style lang="scss" scoped>
.home {
  .hero-section {
    height: 600px;
    position: relative;
    overflow: hidden;
    
    .hero-slider {
      height: 100%;
      position: relative;
    }
    
    .hero-slide {
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      display: flex;
      align-items: center;
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      opacity: 0;
      transition: opacity 0.8s ease-in-out;
      
      &.active {
        opacity: 1;
      }
      
      .hero-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.8) 0%, rgba(118, 75, 162, 0.8) 100%);
        z-index: 1;
      }
      
      .hero-content {
        position: relative;
        z-index: 2;
        width: 100%;
        color: white;
        text-align: center;
        animation: slideInUp 1s ease-out;
        
        .hero-title {
          font-size: 48px;
          font-weight: bold;
          margin-bottom: 20px;
          text-shadow: 0 2px 4px rgba(0,0,0,0.3);
          line-height: 1.2;
        }
        
        .hero-subtitle {
          font-size: 20px;
          margin-bottom: 40px;
          opacity: 0.9;
          max-width: 800px;
          margin-left: auto;
          margin-right: auto;
        }
        
        .hero-actions {
          display: flex;
          gap: 20px;
          justify-content: center;
          flex-wrap: wrap;
          
          .el-button {
            transition: all 0.3s ease;
            
            &:hover {
              transform: translateY(-2px);
              box-shadow: 0 4px 12px rgba(0,0,0,0.2);
            }
          }
        }
      }
    }
    
    // 导航按钮
    .hero-nav {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 100%;
      z-index: 10;
      pointer-events: none;
      
      .nav-btn {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 50px;
        height: 50px;
        border: none;
        background: rgba(255, 255, 255, 0.2);
        color: white;
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.3s ease;
        pointer-events: auto;
        backdrop-filter: blur(10px);
        
        &:hover {
          background: rgba(255, 255, 255, 0.3);
          transform: translateY(-50%) scale(1.1);
        }
        
        &.prev {
          left: 20px;
        }
        
        &.next {
          right: 20px;
        }
        
        i {
          font-size: 20px;
        }
      }
    }
    
    // 指示器
    .hero-indicators {
      position: absolute;
      bottom: 30px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 12px;
      z-index: 10;
      
      .indicator {
        width: 12px;
        height: 12px;
        border: none;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.3s ease;
        
        &:hover {
          background: rgba(255, 255, 255, 0.6);
        }
        
        &.active {
          background: white;
          transform: scale(1.2);
        }
      }
    }
    
    // 控制按钮
    .hero-controls {
      position: absolute;
      top: 30px;
      right: 30px;
      z-index: 10;
      
      .control-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: rgba(255, 255, 255, 0.2);
        color: white;
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.3s ease;
        backdrop-filter: blur(10px);
        
        &:hover {
          background: rgba(255, 255, 255, 0.3);
          transform: scale(1.1);
        }
        
        i {
          font-size: 16px;
        }
      }
    }
  }
  
  // 动画
  @keyframes slideInUp {
    from {
      opacity: 0;
      transform: translateY(30px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .products-section,
  .news-section {
    padding: 80px 0;
    
    .section-header {
      text-align: center;
      margin-bottom: 60px;
      
      .section-title {
        font-size: 36px;
        font-weight: bold;
        color: #2c3e50;
        margin-bottom: 20px;
      }
      
      .section-subtitle {
        font-size: 18px;
        color: #666;
        max-width: 600px;
        margin: 0 auto;
      }
    }
  }

  .products-section {
    background: #fff;
    
    .products-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 30px;
      margin-bottom: 50px;
    }
    
    .product-card {
      background: #fff;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
      transition: transform 0.3s ease;
      
      &:hover {
        transform: translateY(-5px);
      }
      
      .product-image {
        height: 200px;
        overflow: hidden;
        
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      
      .product-content {
        padding: 20px;
        
        .product-name {
          font-size: 18px;
          font-weight: bold;
          margin-bottom: 10px;
          color: #2c3e50;
        }
        
        .product-category {
          color: #666;
          margin-bottom: 15px;
        }
      }
    }
    
    .section-footer {
      text-align: center;
    }
  }



  .news-section {
    background: #fff;
    
    .news-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
      gap: 30px;
      margin-bottom: 50px;
    }
    
    .news-card {
      background: #fff;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
      transition: transform 0.3s ease;
      
      &:hover {
        transform: translateY(-5px);
      }
      
      .news-image {
        height: 200px;
        overflow: hidden;
        position: relative;
        
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
        
        .news-category {
          position: absolute;
          top: 10px;
          left: 10px;
          background: rgba(64, 158, 255, 0.9);
          color: white;
          padding: 4px 8px;
          border-radius: 4px;
          font-size: 12px;
        }
      }
      
      .news-content {
        padding: 20px;
        
        .news-meta {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 15px;
          
          .news-date {
            color: #999;
            font-size: 14px;
          }
          

        }
        
        .news-title {
          font-size: 18px;
          font-weight: bold;
          margin-bottom: 15px;
          color: #2c3e50;
          line-height: 1.4;
        }
        
        .news-desc {
          color: #666;
          margin-bottom: 15px;
          line-height: 1.6;
        }
        
        .news-tags {
          display: flex;
          gap: 8px;
          flex-wrap: wrap;
          margin-bottom: 15px;
        }
        
        .news-actions {
          display: flex;
          justify-content: flex-end;
        }
      }
    }
    
    .section-footer {
      text-align: center;
    }
  }

  .contact-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 80px 0;
    color: white;
    text-align: center;
    
    .contact-title {
      font-size: 36px;
      font-weight: bold;
      margin-bottom: 20px;
    }
    
    .contact-desc {
      font-size: 18px;
      margin-bottom: 40px;
      opacity: 0.9;
    }
    
    .contact-actions {
      display: flex;
      gap: 20px;
      justify-content: center;
    }
  }
}

@media (max-width: 768px) {
  .home {
    .hero-section {
      height: 400px;
      
      .hero-slide {
        .hero-content {
          .hero-title {
            font-size: 28px;
            line-height: 1.3;
          }
          
          .hero-subtitle {
            font-size: 16px;
            margin-bottom: 30px;
          }
          
          .hero-actions {
            flex-direction: column;
            align-items: center;
            gap: 15px;
            
            .el-button {
              width: 200px;
            }
          }
        }
      }
      
      .hero-nav {
        .nav-btn {
          width: 40px;
          height: 40px;
          
          &.prev {
            left: 10px;
          }
          
          &.next {
            right: 10px;
          }
          
          i {
            font-size: 16px;
          }
        }
      }
      
      .hero-indicators {
        bottom: 20px;
        
        .indicator {
          width: 10px;
          height: 10px;
        }
      }
      
      .hero-controls {
        top: 20px;
        right: 20px;
        
        .control-btn {
          width: 35px;
          height: 35px;
          
          i {
            font-size: 14px;
          }
        }
      }
    }
    
    .products-section,
    .news-section {
      padding: 60px 0;
      
      .section-header {
        .section-title {
          font-size: 28px;
        }
      }
    }
    
    .contact-section {
      .contact-actions {
        flex-direction: column;
        align-items: center;
      }
    }
  }
}
</style>

